package sch.jl.caigou.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DbConnection 
{

	public static Connection getConnection() throws ClassNotFoundException,SQLException
	{
		Class.forName("com.mysql.jdbc.Driver");
//		Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		String url="jdbc:mysql://localhost:3306/sbc";
		String user="root";
		String password="1234";
		Connection conn = DriverManager.getConnection(url,user,password);
//		Connection conn = DriverManager.getConnection("jdbc:odbc:XZH");
		return conn;
		
	}
	
	public static void free(Connection conn,Statement st,ResultSet rs)
	{
		try
		{
			if(rs!=null)
			{
				rs.close();
			}
			if(st!=null)
			{
				st.close();
			}
			if(conn!=null)
			{
				conn.close();
			}			
		}
		catch(SQLException e)
		{
			e.printStackTrace();
		}
	}
}
